<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="login.css">
    <title>登录页面</title>
</head>
<body>
<section class="main">
    <figure>
        <figure class="lang">如愿</figure>
        <h2>希望您要你的自由和美好都能如愿</h2>
    </figure>
    <section class="login_white ma_top5">
        <section>
            <form class="Form">
                <div class="input_text">
                    <input type="text" placeholder="手机号/邮箱/用户名" id="userName"/>
                    <span></span>
                </div>
                <div class="input_text ma_top5">
                    <input type="password" placeholder="密码" id="password"/>
                    <span></span>
                </div>
                <div class="input_text ma_top5">
                    <input id="veryCode" name="veryCode" placeholder="请输入验证码" type="text"/>
                    <span></span>
                </div>
                <div class="input_text ma_top5">
                    <div class="chanIg">
                        <img id="imgSrc" alt="验证码" src="http://192.168.191.2:8080/SpringHibernateWish/verify/code"/>
                    </div>
                    <div class="changeImg">
                        <input type="button" value="换一张" onclick="changeImg()" class="chengeImg">
                    </div>
                </div>
                <div class="input_text ma_top5">
                    <input type="checkbox" class="check">
                    <label>记住密码</label>
                </div>
                <div class="input_text ma_top10">
                    <input type="button" value="登&ensp;&ensp;&ensp;录" class="login_btn" onclick="loginAction()">
                </div>
                <div class="input_text ma_top5 la_color">
                    <a href="<c:url value='/user/toForgetPasswordPage'/>" class="la_pass">忘记密码？</a>
                    <a href="register.jsp" class="la_register">立即注册</a>
                </div>
            </form>
        </section>
    </section>
</section>
<script src="jquery-2.1.1.js"></script>
<script src="md5.js"></script>
<script>
    /*改变验证码*/
    $(".chengeImg").click(function () {
        $("#imgSrc").attr("src",$("#imgSrc").attr("src")+ "?nocache=" + new Date().getTime());
    });
    /*改变验证码end*/

    function loginAction() {
        var password = $("#password").val();
        var userName = $("#userName").val();
        var veryCode = $("#veryCode").val();
        $(".Form").find("span").text("");
        if (userName == null || userName == undefined || userName.trim() == "") {
            $("#userName").next("span").text("用户名不能为空");
            return;
        }
        if (userName.length < 2 || userName.length > 9) {
            $("#userName").next("span").text("用户名长度不合法");
            return;
        }
        if (password == null || password == undefined || password.trim() == "") {
            $("#password").next("span").text("密码不能为空");
            return;
        }
        if (password.length < 6) {
            $("#password").next("span").text("密码必须大于6位");
            return;
        }
        if (veryCode == null || veryCode == undefined || veryCode.trim() == "") {
            $("#veryCode").next("span").text("验证码不能为空");
            return;
        }
    /*    $.ajax({
            url: "<c:url value='/login'/>",
            data: {"password": hex_md5(password), "userName": userName, "loginDevice": "1", "veryCode": veryCode},
            type: "POST",
            dataType: "JSON",
            success: function (data) {

                if (data == null || data == undefined) {
                    alert("登录失败，请稍后重试");
                } else if (data.codeC != veryCode.toUpperCase()) {
                    $("#veryCode").next("span").text("验证码错误");
                    changeImg();
                    return;
                } else {
                    if (data.code == 0) {
                        alert(data.msg);
                        window.location.href = "<c:url value='/main'/>";
                    } else {
                        alert(data.msg);
                        changeImg();
                    }
                }
            }
        });*/
        $.ajax({
                    type: "post",
                    url: "http://192.168.191.2:8080/SpringHibernateWish/loginByWeb",
                    dataType: "JSONP",
                    synec: true,
                    data: {
                        "userName": name,
                        "password": hex_md5(pass), /*提交给后台的数据格式*/
                        "loginDevice": "",//判断用pc还是移动端登录;
                        "veryCode": imgVal,//验证码;
                    },
                    jsonp: "callbackparam",//callbackparam后台接受数据的类型的函数
                    jsonpCallback: "success_jsonpCallback",//固定的写法
                    success: function (json) {
                        alert(json.msg);
                    },
                    error: function () {
                        alert("错误");
                    }


                }
        )
    }
</script>
</body>
</html>